import express from 'express'
import { upload } from '../components/imageUpload.js'
const router = express.Router()

//实现上传业务
//单文件上传
router.post('/uloadone',upload.single('file'),async(req,res)=>{
    console.log('保存成功的文件',req.file)
    res.send({message:'上传成功',info:{ url:req.file.path.replace('public','') }})
})

//多个文件上传
// upload.array(字段名称,限制数量?)
router.post('/uloadmany',upload.array('file'),async(req,res)=>{
    console.log('保存成功的文件',req.file)
    res.send({message:'上传成功',info:{ url:req.files.map(item=>item.path.replace('public','')) }})
})

export default router